package com.dcw.lixb.designmode.interpreter;

/**
 * @author lixiaobin
 * @date 2020-07-28 14:29:40
 * @desc 描述信息
 */
public class InterpreterMain {

    //规则: Robert 和 John 是男性
    public static Expression getMaleExpression() {
        TerminalExpression robert = new TerminalExpression("Robert");
        TerminalExpression john = new TerminalExpression("John");
        return new OrExpression(robert, john);
    }

    //规则: Julie 是一个已婚的女性
    public static Expression getMarriedWomanExpression() {
        TerminalExpression julie = new TerminalExpression("Julie");
        TerminalExpression married = new TerminalExpression("Married");
        return new AndExpression(julie, married);
    }

    public static void main(String[] args) {
        Expression isMale = getMaleExpression();
        Expression isMarriedWoman = getMarriedWomanExpression();

        System.out.println("张三 is male ? " + isMale.interpret("张三"));
        System.out.println("John is male ? " + isMale.interpret("John"));
        System.out.println("Julie is married woman ? " + isMarriedWoman.interpret("Julie"));
    }
}
